package jmine.tec.purge.dao;

import java.util.List;

import jmine.tec.purge.api.PurgeHelper;
import jmine.tec.purge.api.Purger;
import jmine.tec.purge.domain.PurgeRequest;
import bancosys.tec.persist.dao.BaseDAO;
import bancosys.tec.utils.date.Date;

/**
 * Expurgador de PurgeRequest.
 * 
 * @author Marcio Ribeiro (mmr)
 * @created Aug 8, 2011
 */
public class PurgeRequestPurger extends BaseDAO<PurgeRequest> implements Purger {

    /**
     * {@inheritDoc}
     */
    public int purge(Date maxDate, int maxWindowSize) {
        List<Long> ids = PurgeHelper.getIds(createCriteria(), "requestEndTime", maxDate, maxWindowSize);
        return getSession().createQuery(PurgeHelper.createDeleteQuery("PurgeRequest", ids)).executeUpdate();
    }

    /**
     * {@inheritDoc}
     */
    public int countItemsToPurge(Date maxDate) {
        return PurgeHelper.countItemsToPurge(createCriteria(), "requestEndTime", maxDate);
    }
}
